using IStrong.EC.Abstractions.Interfaces;
using System;
using System.Collections.Generic;
using System.Text;

namespace IStrong.EC.WebApi.Results.Entity
{
    /// <summary> 
    /// 服务合同盘点表各小组年目标
    /// </summary> 
    public class MaintenancePlan
    {
        /// <summary> 
        /// ID
        /// </summary> 
        public int Id { get; set; }

        /// <summary> 
        /// 责任区域
        /// </summary> 
        public string Territory { get; set; }

        /// <summary>
        /// 总目标
        /// </summary>
        public decimal Summation { get { return ResponsibilityTarget + AreaTarget + OperationTarget; } }
        /// <summary> 
        /// 责任目标（自签）
        /// </summary> 
        public decimal ResponsibilityTarget { get; set; }

        /// <summary> 
        /// 大区目标（协签）
        /// </summary> 
        public decimal AreaTarget { get; set; }

        /// <summary> 
        /// 运营组目标
        /// </summary> 
        public decimal OperationTarget { get; set; }

        /// <summary> 
        /// 计划时间
        /// </summary> 
        private DateTime _PlanTime { get; set; }

        /// <summary>
        /// 计划时间
        /// </summary>
        public string PlanTime
        {
            get
            {
                if (null != _PlanTime)
                {
                    return _PlanTime.ToString("yyyy-MM-dd");
                }
                return string.Empty;
            }
            set
            {
                if (!string.IsNullOrWhiteSpace(value))
                    _PlanTime = DateTime.Parse(value);
            }
        }
        /// <summary>
        /// 合计完成额
        /// </summary>
        public decimal SummationDone { get { return ResponsibilityDone + AreaDone + OperationDone; } }

        /// <summary>
        /// 服务主跟完成额
        /// </summary>
        public decimal ResponsibilityDone { get; set; }

        /// <summary>
        /// 大区主跟完成额
        /// </summary>
        public decimal AreaDone { get; set; }

        /// <summary>
        /// 运营主跟完成额
        /// </summary>
        public decimal OperationDone { get; set; }

        /// <summary>
        /// 合计完成率
        /// </summary>
        public decimal SummationPercentage
        {
            get
            {
                if (SummationDone >= Summation && SummationDone > 0 && Summation > 0)
                {
                    return 100;
                }
                else if (SummationDone < Summation && SummationDone > 0)
                {
                    return Math.Round(SummationDone / Summation * 100,2);
                }
                else
                {
                    return 0;
                }
            }
        }

        /// <summary>
        /// 服务主跟完成率
        /// </summary>
        public decimal ResponsibilityPercentage
        {
            get
            {
                if (ResponsibilityDone >= ResponsibilityTarget && ResponsibilityDone >0 && ResponsibilityTarget > 0)
                {
                    return 100;
                }
                else if (ResponsibilityDone < ResponsibilityTarget && ResponsibilityDone > 0)
                {
                    return Math.Round(ResponsibilityDone / ResponsibilityTarget * 100,2);
                }
                else
                {
                    return 0;
                }
            }
        }

        /// <summary>
        /// 大区主跟完成率
        /// </summary>
        public decimal AreaPercentage
        {
            get
            {
                if (AreaDone >= AreaTarget && AreaDone >0 && AreaTarget > 0)
                {
                    return 100;
                }
                else if (AreaDone < AreaTarget && AreaDone > 0)
                {
                    return Math.Round(AreaDone / AreaTarget * 100,2);
                }
                else
                {
                    return 0;
                }
            }
        }

        /// <summary>
        /// 运营主跟完成率
        /// </summary>
        public decimal OperationPercentage
        {
            get
            {
                if (OperationDone >= OperationTarget && OperationDone > 0 && OperationTarget > 0)
                {
                    return 100;
                }
                else if (OperationDone < OperationTarget && OperationDone > 0)
                {
                    return Math.Round(OperationDone / OperationTarget * 100,2);
                }
                else
                {
                    return 0;
                }
            }
        }
    }
}

